package com.hinnotek.amoeba.ui.activity.old

import android.os.Bundle
import androidx.activity.viewModels
import com.lee.common.base.BaseActivity
import com.hinnotek.amoeba.R
import com.hinnotek.amoeba.bean.old.AmibaTemporaryeByIdBean
import com.hinnotek.amoeba.databinding.ActivityRenewalPaymentDetailBinding
import com.hinnotek.amoeba.dialog.CustomDialog
import com.hinnotek.amoeba.utilities.ToastUtils
import com.hinnotek.amoeba.viewmodels.AmibaViewModel
import com.lee.common.network.net.ObserverState
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class RenewalPaymentDetailActivity : BaseActivity<ActivityRenewalPaymentDetailBinding>() {

    val viewModel by viewModels<AmibaViewModel>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLeftVisible(true)
        setTitle("临时缴费/续费申请")

        setContentView(R.layout.activity_renewal_payment_detail)
    }

    override fun initVew() {
    }

    override fun setData() {
        val amibaTemporaryId = intent.getIntExtra("amibaTemporaryId", 0)
        getAmibaTemporaryeById(amibaTemporaryId)
    }

    /**
     * app端通过id查询单个临时缴费续费申请接口
     */
    fun getAmibaTemporaryeById(amibaTemporaryId: Int) {
        val customDialog = CustomDialog(mContext, "正在加载...")
        customDialog.show()

        viewModel.getAmibaTemporaryeById(amibaTemporaryId)
            .observe(this, object : ObserverState<AmibaTemporaryeByIdBean>() {
                override fun onDataChange(data: AmibaTemporaryeByIdBean) {
                    customDialog.dismiss()

                    bindingView.tvRpPayTotal.text = data.customerName
                    bindingView.tvRpChooseProject.text = data.projectName
                    bindingView.tvRpLocation.text = data.usePosition
                    bindingView.tvRpNum.text = data.payNum
                    bindingView.tvRpFlow.text = data.flowQuota
                    bindingView.tvRpPayTotal.text = data.payTotal
                    bindingView.tvRpApplicant.text = data.createUser
                    bindingView.tvRpApprover.text = data.approvalUser
                    if (data.approvalState == 1) {
                        bindingView.tvApproverStatus.text = "已申请"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.black))
                    } else if (data.approvalState == 2) {
                        bindingView.tvApproverStatus.text = "已同意"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_btn_green_normal_color))
                    } else if (data.approvalState == 3) {
                        bindingView.tvApproverStatus.text = "已拒绝"
                        bindingView.tvApproverStatus.setTextColor(getColor21(R.color.xui_config_color_red))
                    }
                    bindingView.tvRpCc.setText(data.sendUser)

                    super.onDataChange(data)
                }

                override fun onError(msg: String?, code: Int) {
                    ToastUtils.showShort(mContext, msg)
                    customDialog.dismiss()
                    super.onError(msg, code)
                }

            })

    }
}